<?php
require_once('../scripts/db.php');
include("includes/functions.php");

$user = mysql_real_escape_string($_GET['username']);
$query = "SELECT * FROM `papptweet` WHERE username = '$user'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

if ($_POST) {

$user = mysql_real_escape_string($_POST['username']);

if ($_POST['Unsub'] == 1) {

$query = "DELETE FROM `papptweet` WHERE username = '$user'";
mysql_query($query) or die(mysql_error());

$url = "http://twitter.com/friendships/destroy/". $user .".json";

$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

header("Location: unsubthanks.php");

} else {

$postcode = $_POST['txtPostcode'];
$area = $_POST['radAlertAreaSize'];

if (!IsPostcode($postcode)) { $error[] = "<li>Please enter a valid UK Postcode</li>"; }

if (count($error) == 0) {
$postcode = str_replace(" ", "", $postcode);

$query = "UPDATE `papptweet` SET `postcode` = '$postcode', `area` = '$area' WHERE username = '$user'";
mysql_query($query) or die(mysql_error());

header("Location: changethanks.php");
}

}

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Twitterplan | Unsubscribe / Change Settings</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
<div id="main">
<img src="images/logo.jpg" alt="TwittertPlan Alpha" width="315" height="62" />
<img src="images/bird.jpg" alt="TwitterPlan Mascot" width="228" height="238" id="mascot" />
<div id="thankswrapper">
<h2>Unsubscribe / Change Settings</h2>
<p>To change the settings for your account, or unsubscribe, please fill out the form below</p>
</div>
<form action="" method="post" class="changeform">
<input type="hidden" name="username" value="<?php echo $row['username']; ?>" />
   <ul id="ulSignup" class="form nobullets">
        <li id="liPostcode">
           <label for="txtPostcode"><span class="number">1.</span> Change your postcode</label>

            <input name="txtPostcode" type="text" class="textbox" id="txtPostcode" value="<?php echo strtoupper($row['postcode']); ?>" />
</li>
        <li id="liAlertArea">
            <p id="pAlertArea"><span class="number">2.</span> Change area size</p>
            <fieldset>
                <ul id="ulAlertArea" class="form nobullets">

                  <li>
                        <input id="radAlertAreaSize_street" name="radAlertAreaSize" value="s" type="radio" <?php if ($row['area'] == "s") echo "checked=\"checked\""; ?> />
                    <label for="radAlertAreaSize_street">My street (approximately 200 m)</label></li>
                    <li>
                        <input id="radAlertAreaSize_neihgbourhood" name="radAlertAreaSize" value="m"  type="radio" <?php if ($row['area'] == "m") echo "checked=\"checked\""; ?> />                                    
                        <label for="radAlertAreaSize_neihgbourhood">My neighbourhood  (approximately 800 m)</label>
                    </li>
                    <li>
                        <input id="radAlertAreaSize_town" name="radAlertAreaSize" value="l" type="radio" <?php if ($row['area'] == "l") echo "checked=\"checked\""; ?> />                                    
                        <label for="radAlertAreaSize_town">Wider area  (approximately 2000 m)</label>
                    </li>
                </ul>
            </fieldset>
        </li>    
		        <li id="step4">

           <label for="Unsub"><span class="number">3.</span> Unsubscribe?</label>

            <input class="textbox" id="Unsub" name="Unsub" type="checkbox" value="1" /> </li>
		</ul>
  <button type="submit" name="submit" id="change"><img src="images/submitbutton.gif" alt="Submit" width="163" height="46" /></button>    
</form>
</div>
<div id="footer" class="changef">
<p>powered by: <a href="http://www.twitter.com"><img src="images/twitter.gif" alt="twitter" border="0" /></a> <a href="http://www.planningalerts.com"><img src="images/planningalerts.gif" alt="Planning Alerts" border="0" /></a> built by: <a href="http://www.lichfielddc.gov.uk"><img src="images/ldc.gif" alt="Lichfield District Council" border="0" /></a> made pretty by <a href="http://www.lincoln.gov.uk"><img src="images/lincoln.gif" alt="City of Lincoln Council" border="0" /></a> and <a href="http://twitter.com/michaeldpollard">@MichaelDPollard</a></p>
</div>
</div>
<style type='text/css'>@import url('http://s3.amazonaws.com/getsatisfaction.com/feedback/feedback.css');</style>
<script src='http://s3.amazonaws.com/getsatisfaction.com/feedback/feedback.js' type='text/javascript'></script>
<script type="text/javascript" charset="utf-8">
  var tab_options = {}
  tab_options.placement = "left";  // left, right, bottom, hidden
  tab_options.color = "#222"; // hex (#FF0000) or color (red)
  GSFN.feedback('http://getsatisfaction.com/twitterplan/feedback/topics/new?display=overlay&style=question', tab_options);
</script>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-511839-14");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>
